package com.xy.biz.mes.domain.converter;

import java.util.Collection;
import java.util.List;

import com.xy.biz.mes.domain.bo.ManufactureTaskBO;
import com.xy.biz.mes.domain.query.ManufactureTaskByIdQuery;
import com.xy.biz.mes.domain.query.ManufactureTaskQuery;
import com.xy.biz.mes.domain.po.ManufactureTaskPO;
import com.xy.biz.mes.domain.req.GetManufactureTaskRequest;
import com.xy.tool.util.BeanUtilsEx;
import com.xy.biz.mes.domain.resp.GetManufactureTaskResponse;
import com.xy.biz.mes.domain.req.SaveManufactureTaskRequest;
import com.xy.biz.mes.domain.req.ListManufactureTaskRequest;

/**
 *
 *
 * @author zsp
 * @date 2022-1-6
 */
public class ManufactureTaskConverter {

    public static ManufactureTaskPO toPO(ManufactureTaskBO source) {
        return BeanUtilsEx.copyProperties(source, () -> new ManufactureTaskPO(), true);
    }

    public static List<ManufactureTaskPO> toPO(Collection<ManufactureTaskBO> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, () -> new ManufactureTaskPO(), true);
    }

    public static ManufactureTaskBO fromPO(ManufactureTaskPO source) {
        return BeanUtilsEx.copyProperties(source, () -> new ManufactureTaskBO());
    }

    public static List<ManufactureTaskBO> fromPO(Collection<ManufactureTaskPO> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, () -> new ManufactureTaskBO());
    }

    public static ManufactureTaskBO toBO(SaveManufactureTaskRequest source) {
        return BeanUtilsEx.copyProperties(source, () -> new ManufactureTaskBO(),
                (s, t) -> {
                    t.setGoodsList(ManufactureTaskGoodsConverter.toBO(s.getGoodsList()));
                    t.setEquipmentList(ManufactureTaskEquipmentConverter.toBO(s.getEquipmentList()));
                    t.setRecordList(ManufactureTaskRecordConverter.toBO(s.getRecordList()));
                });
    }

    public static List<ManufactureTaskBO> toBO(Collection<SaveManufactureTaskRequest> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, () -> new ManufactureTaskBO(),
                (s, t) -> {
                    t.setGoodsList(ManufactureTaskGoodsConverter.toBO(s.getGoodsList()));
                    t.setEquipmentList(ManufactureTaskEquipmentConverter.toBO(s.getEquipmentList()));
                    t.setRecordList(ManufactureTaskRecordConverter.toBO(s.getRecordList()));
                });
    }

    public static GetManufactureTaskResponse toResponse(ManufactureTaskBO source) {
        return BeanUtilsEx.copyProperties(source, () -> new GetManufactureTaskResponse());
    }

    public static List<GetManufactureTaskResponse> toResponse(Collection<ManufactureTaskBO> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, () -> new GetManufactureTaskResponse());
    }

    public static ManufactureTaskQuery toQuery(ListManufactureTaskRequest source) {
        if (null == source) {
            return null;
        }
        ManufactureTaskQuery target = new ManufactureTaskQuery(source.getPageIndex(), source.getPageSize());
        BeanUtilsEx.copyProperties(source, target);
        return target;
    }

    public static ManufactureTaskByIdQuery toQuery(GetManufactureTaskRequest source) {
        return BeanUtilsEx.copyProperties(source, ManufactureTaskByIdQuery::new);
    }

}
